<template>
	<view>
		<u-toast ref="uToast" />
		<u-no-network></u-no-network>
		<u-navbar title="服务商品" safeAreaInsetTop fixed placeholder>
			<view class="coreshop-navbar-left-slot" slot="left">
				<u-icon name="arrow-left" size="19" @click="goNavigateBack"></u-icon>
				<u-line direction="column" :hairline="false" length="16" margin="0 8px"></u-line>
				<u-icon name="home" size="22" @click="goHome"></u-icon>
			</view>
			<view slot="right">
			</view>
		</u-navbar>
		<view class="content">
			<view v-if="list.length>0">
				<view class="orderList" v-for="(item, index) in list" :key="index">
					<view
						class="item coreshop-solid-bottom coreshop-margin-top-5 coreshop-margin-padding-10 coreshop-padding-bottom-5">
						<view class="left">
							<u--image :showLoading="true" :src="item.thumbnail" width="140px" height="140px"></u--image>
						</view>
						<view class="content">
							<view class="title u-line-2">{{item.title}}</view>
							<view class="type u-line-3">{{item.description}}</view>
							<view class="coreshop-text-price coreshop-text-red coreshop-margin-bottom-5">
								{{ item.money }}</view>
							<view class="delivery-time">最大购买限制：{{item.maxBuyNumber== 0 ? '不限' : item.maxBuyNumber}}
							</view>
						</view>
					</view>
					<view
						class="coreshop-text-gray coreshop-font-xs coreshop-flex coreshop-flex-nowrap coreshop-padding-10 coreshop-solid-bottom">
						兑换级别：
						<view class="coreshop-text-gray coreshop-font-xs coreshop-flex coreshop-flex-nowrap"
							v-if="item.allowedMemberships && item.allowedMemberships.length>0">
							<view class="coreshop-width-fit-content coreshop-margin-right-5"
								v-for="(item, indexChild) in item.allowedMemberships" :key="indexChild">
								<u-tag :text="item" :plain="true" mode="light" size="mini" />
							</view>
						</view>
					</view>
					<view
						class="coreshop-text-gray coreshop-font-xs coreshop-flex coreshop-flex-nowrap coreshop-padding-10 coreshop-solid-bottom">
						兑换门店：
						<view class="coreshop-text-gray coreshop-font-xs coreshop-flex coreshop-flex-nowrap"
							v-if="item.consumableStores && item.consumableStores.length>0">
							<view class="coreshop-bg-orange-light sm  coreshop-padding-4 coreshop-margin-right-5"
								v-for="(item, indexChild) in item.consumableStores" :key="indexChild">{{item}}</view>
						</view>
					</view>
					<view
						class="coreshop-flex coreshop-align-center coreshop-flex-direction-row coreshop-justify-between coreshop-padding-10">
						<view class="coreshop-text-right coreshop-time-right"
							v-if="item.openStatus == 1 && item.timestamp > 0">
							<u-count-down :time="item.timestamp * 1000" :autoStart="true" :millisecond="true"
								format="DD天HH时mm分ss秒" @change="onChange($event,index)">
								<view class="time coreshop-font-11 coreshop-text-gray">
									<view class="">仅剩时间：</view>
									<view class="time__custom">
										<text class="time__custom__item">{{ item.timeData.days }}</text>
									</view>
									<text class="time__doc">天</text>
									<view class="time__custom">
										<text
											class="time__custom__item">{{ item.timeData.hours>=10?item.timeData.hours:'0'+item.timeData.hours}}</text>
									</view>
									<text class="time__doc">:</text>
									<view class="time__custom">
										<text class="time__custom__item">{{ item.timeData.minutes }}</text>
									</view>
									<text class="time__doc">:</text>
									<view class="time__custom">
										<text class="time__custom__item">{{ item.timeData.seconds }}</text>
									</view>
								</view>
							</u-count-down>
						</view>
						<view class="coreshop-text-right coreshop-time-right"
							v-if="item.openStatus == 2 && item.timestamp > 0">
							<u-count-down :time="item.timestamp * 1000" :autoStart="true" :millisecond="true"
								format="DD天HH时mm分ss秒" @change="onChange($event,index)">
								<view class="time coreshop-font-11 coreshop-text-gray">
									<view class="">距离开始：</view>
									<view class="time__custom">
										<text class="time__custom__item">{{ item.timeData.days }}</text>
									</view>
									<text class="time__doc">天</text>
									<view class="time__custom">
										<text
											class="time__custom__item">{{ item.timeData.hours>=10?item.timeData.hours:'0'+item.timeData.hours}}</text>
									</view>
									<text class="time__doc">:</text>
									<view class="time__custom">
										<text class="time__custom__item">{{ item.timeData.minutes }}</text>
									</view>
									<text class="time__doc">:</text>
									<view class="time__custom">
										<text class="time__custom__item">{{ item.timeData.seconds }}</text>
									</view>
								</view>
							</u-count-down>
						</view>
						<view class="coreshop-text-right coreshop-time-right" v-if="item.openStatus == 3">
							<view class="time coreshop-font-11 coreshop-text-gray">
								<view class="">活动已结束</view>
							</view>
						</view>
						<view v-if="item.openStatus == 3">
							<u-button shape="square" size="small" :plain="true">活动已结束</u-button>
						</view>
						<view v-if="item.openStatus != 3">
							<u-button type="warning" shape="square" size="small" @click="goServicesDetail(item.id)">立刻抢购
							</u-button>
						</view>
					</view>
				</view>
				<u-loadmore :status="status" :icon-type="iconType" :load-text="loadText" margin-top="20"
					margin-bottom="20" />
			</view>

			<!-- 无数据时默认显示 -->
			<view class="coreshop-emptybox" v-else>
				<u-empty :icon="$globalConstVars.apiFilesUrl+'/static/images/empty/history.png'" icon-size="150"
					text="暂无服务列表" mode="list"></u-empty>
			</view>
		</view>
		<!-- 登录提示 -->
		<coreshop-login-modal></coreshop-login-modal>
	</view>

</template>

<script>
	export default {

		data() {
			return {
				page: 1,
				limit: 10,
				list: [],
				status: 'loadmore',
				iconType: 'flower',
				loadText: {
					loadmore: '轻轻上拉',
					loading: '努力加载中',
					nomore: '实在没有了'
				}
			};
		},
		onLoad() {
			this.getServicelist()
		},
		onShow() {},
		onReachBottom() {
			if (this.status === 'loadmore') {
				this.getServicelist()
			}
		},
		methods: {
			getServicelist() {
				let _this = this;
				let data = {
					page: this.page,
					limit: this.limit
				}
				this.status = 'loading'
				this.$u.api.getServicelist(data).then(res => {
					if (res.status) {
						let _list = res.data.list
						this.list = [...this.list, ..._list]
						if (res.data.count > _this.list.length) {
							_this.page++
							_this.status = 'loadmore'
						} else {
							_this.status = 'nomore'
						}
					} else {
						_this.$u.toast(res.msg)
					}
				})
			},
			onChange(e, key) {
				this.$set(this.list[key], 'timeData', e)
			},
		}
	};
</script>

<style lang="scss">
	.orderList {
		.title {
			font-size: 18px;
			font-weight: bolder;
		}
	}
</style>
